package com.hc.server.user.controller;

import com.hc.server.common.domain.vo.request.PageBaseReq;
import com.hc.server.common.domain.vo.response.ApiResult;
import com.hc.server.common.domain.vo.response.PageBaseResp;
import com.hc.server.common.utils.RequestHolder;
import com.hc.server.user.domain.vo.request.friend.FriendApplyReq;
import com.hc.server.user.domain.vo.request.friend.FriendApproveReq;
import com.hc.server.user.domain.vo.response.friend.FriendApplyResp;
import com.hc.server.user.service.FriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by wdj on 2024/10/22
 */
@RestController
@RequestMapping("/hc/user/friend")
@Api(tags = "好友相关接口")
@Slf4j
public class FriendController {

    @Autowired
    private FriendService friendService;

    @PostMapping
    @ApiOperation("申请好友")
    public ApiResult<Void> apply(@Valid @RequestBody FriendApplyReq request){
        Long uid = RequestHolder.get().getUid();
        friendService.apply(uid, request);
        return ApiResult.success();
    }

    @GetMapping("/apply/page")
    @ApiOperation("好友申请列表")
    public ApiResult<PageBaseResp<FriendApplyResp>> page(@Valid PageBaseReq request) {
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.pageApplyFriend(uid, request));
    }

    @PutMapping("/apply")
    @ApiOperation("审批同意")
    public ApiResult<Void> applyApprove(@Valid @RequestBody FriendApproveReq request) {
        friendService.applyApprove(RequestHolder.get().getUid(), request);
        return ApiResult.success();
    }
}
